{extend name="base/base" /}
{block name="content"}
<form class="layui-form" id="ajaxform" onsubmit="return false">
  <div class="layui-form-item">
    <label class="layui-form-label">正文：</label>
  </div>
  <div class="layui-form-item">
    <textarea id="demo" style="display: none;" name='content'></textarea>
  </div>
  <div class="site-demo-button" style="margin-top: 20px;">
    <button class="layui-btn site-demo-layedit" data-type="ajax">立即提交</button>
    <button onclick="cancel()" class="layui-btn layui-btn-primary">取消</button>
  </div>
</form>
{/block}
{block name="script"}
<script>
layui.use(['form', 'layedit'], function(){
  var layedit = layui.layedit;
  var form = layui.form;
  layedit.set({
      uploadImage: {
        url: '{:C("system_url")}/api/Upload/upload_img2'
        ,type: 'post' //默认post
      }
    });
  var text = layedit.build('demo',{
    height: 500 //设置编辑器高度
  }); //建立编辑器
  var str = '{$pravicy}';
  $("#demo").val(str);
  //编辑器外部操作
  var active = {
    ajax: function(){
      layedit.sync(text);
      var post_data = $("#ajaxform").serialize();
      $.ajax({
            url:"{:url('admin/xieyi/aboutUs')}",
            type:"POST",
            data:post_data,
            success:function(ret){
                if (ret.code == 1) {
                    layer.msg('操作成功');
                    location.reload();
                }
                if (ret.code == 0) {
                    layer.msg(ret.msg);
                }
            }
        });
    }
  };
  $('.site-demo-layedit').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
  function cancel(){
    window.location.href=document.referrer;
  }
</script>
</script>
{/block}